﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Paint.DisplayCoverage.CUiPaintDisplayCoverageEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Paint.PaintDuringSimulation;
using EngineeringInternalExtension;
using EngineeringInternalExtension.DataTypes.Paint;
using System.Collections.Generic;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.Paint.DisplayCoverage;

public class CUiPaintDisplayCoverageEnabler : ITxCommandEnabler
{
  public CUiPaintDisplayCoverageEnabler()
  {
    this.RegisterToEvents();
    if (!TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
      return;
    this.LoadPaintSettingsNecessaryForLoadStudyFromRegistry();
    CUiPaintDisplayCoverageUtil.RedrawMeshesUsingCurrentScale();
  }

  internal void RegisterToEvents()
  {
    TxApplication.DocumentCollection.DocumentLoaded += new TxDocumentCollection_DocumentLoadedEventHandler(this.OnDocumentLoaded);
    TxApplication.DocumentCollection.StudyModeChanged += new TxDocumentCollection_StudyModeChangedEventHandler(this.OnStudyModeChanged);
  }

  internal void UnregisterFromEvents()
  {
    TxApplication.DocumentCollection.DocumentLoaded -= new TxDocumentCollection_DocumentLoadedEventHandler(this.OnDocumentLoaded);
    TxApplication.DocumentCollection.StudyModeChanged -= new TxDocumentCollection_StudyModeChangedEventHandler(this.OnStudyModeChanged);
  }

  private void LoadPaintCoverage()
  {
    if (CApPaintDuringSimulationManager.Instance.UsePaintThickness)
      CUiPaintDisplayCoverageUtil.ReloadFiles();
    this.LoadPaintSettingsNecessaryForLoadStudyFromRegistry();
    CUiPaintDisplayCoverageUtil.UpdateMeshVisibility();
    CUiPaintDisplayCoverageUtil.RedrawMeshesUsingCurrentScale();
  }

  private void OnStudyModeChanged(
    object sender,
    TxDocumentCollection_StudyModeChangedEventArgs args)
  {
    this.LoadPaintCoverage();
  }

  private void OnDocumentLoaded(object sender, TxDocumentCollection_DocumentLoadedEventArgs args)
  {
    this.LoadPaintCoverage();
  }

  private void LoadPaintSettingsNecessaryForLoadStudyFromRegistry()
  {
    string str = CUiPaintDisplayCoverageUtil.LoadThicknessScaleNameFromRegistry();
    TxApplicationEx.PaintManager().SetThicknessScaleByName(str);
    List<TxColor> txColor = CUiPaintDisplayCoverageUtil.ConvertToTxColor(CUiPaintDisplayCoverageUtil.LoadColorListFromRegistry());
    TxApplicationEx.PaintManager().SetCoverageColorMap(txColor);
    bool flag = CUiPaintDisplayCoverageUtil.LoadDisplayCoverageModeFromRegistry();
    TxPaintSettings paintSettings = TxApplicationEx.PaintManager().PaintSettings;
    paintSettings.DisplayCoverageMode = flag;
    TxApplicationEx.PaintManager().PaintSettings = paintSettings;
  }

  public bool Enable
  {
    get
    {
      bool flag = TxApplication.ActiveDocument.SimulationPlayer.IsSimulationRunning();
      return TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded() && !flag;
    }
  }
}
